<template>
	<el-dialog v-model="dialogFormVisible" title='审核产品' width="30%" center>
		<div class="describe">确定审核此产品的出库吗？</div>
		<el-radio-group v-model="formData.product_out_status" class="ml-4">
			<el-radio label="同意" size="large">同意</el-radio>
			<el-radio label="否决" size="large">否决</el-radio>
		</el-radio-group>
		<el-input type="textarea" placeholder="请输入审核备注" v-model="formData.audit_memo" />
		<template #footer>
			<span class="dialog-footer">
				<el-button type="primary" @click="productAudit">
					确定
				</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import {reactive, ref} from 'vue'
import {auditProduct} from '@/api/product/index'
import type {auditProductForm} from '@/api/product/type'
import {useUserInfo} from '@/store/modules/userinfo'
import { ElMessage } from "element-plus"
import { tracking } from '@/utils/operation.js'
const dialogFormVisible = ref<boolean>(false)
const userStore = useUserInfo()
const formData:auditProductForm = reactive({
		id: 0,
		product_name:'',
		product_out_id: 0,
		product_out_status: '',
		audit_memo: '',
		product_out_price: 0,
		product_out_audit_person: userStore.name,
		product_out_apply_person: '',
    	product_in_warehouse_number: 0,
		product_single_price: 0,
		product_out_number: '',
		product_apply_time:''
	})
//确定
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const productAudit = async()=>{
    const res = await auditProduct(formData)
    if(res.status == 0){
        ElMessage({
            type:'success',
            message:'操作成功'
        })
        dialogFormVisible.value = false
        emit('success')
		tracking('产品', localStorage.getItem('name'), formData.product_name, '高级',formData.product_out_status)
    }else{
        ElMessage({
            type:'error',
            message:'操作失败'
        })
    }
}
const open = (row:any)=>{
    Object.assign(formData,{...row})
    dialogFormVisible.value = true
}
defineExpose({
    open
})
</script>

<style lang="scss" scoped>
	.describe {
		margin-bottom: 8px;
	}
</style>
